﻿using System;
using System.Collections;
using Caliburn.PresentationFramework.ApplicationModel;

namespace Luna.WPF.ApplicationFramework
{
    public interface IDockablePresenter : IPresenter
    {
        void Show();
        void ShowRibbon();
    }

    public class DockingPresenter : DefaultPresenter
    {
        private readonly IDockSitePresenter _dockSitePresenter;

        public DockingPresenter()
        {
            _dockSitePresenter = _container.Resolve<IDockSitePresenter>();
        }

        public virtual void Show()
        {
            _dockSitePresenter.Show(this);
        }

        protected override void OnShutdown()
        {
            base.OnShutdown();
        }

        public virtual void ShowRibbon()
        {
            _dockSitePresenter.ShowRibbon(this);
        }

        public virtual IPresenter Open<T>() where T : IPresenter
        {
            var presenter = _container.Resolve<T>();
            _dockSitePresenter.Show(presenter);
            return presenter;
        }

        public virtual IPresenter Open<T>(IDictionary values) where T : IPresenter
        {
            var presenter = _container.Resolve<T>(values);
            _dockSitePresenter.Show(presenter);
            return presenter;
        }

        public virtual void Activate(object model)
        {
            _dockSitePresenter.Activate(model);
        }

        public T GetActiveModel<T>() where T : class
        {
            return _dockSitePresenter.GetActiveModel<T>();
        }

        public T FirstOrDefault<T>(Func<T, bool> predicate) where T : IPresenter
        {
            return _dockSitePresenter.FirstOrDefault(predicate);
        }
    }
}
